//
//  UITest.m
//  SimpleUITest
//
//  Created by Ofri Wolfus on 06/03/07.
//  Copyright 2007 Ofri Wolfus. All rights reserved.
//

#import "UITest.h"


@implementation UITest

- (id)init {
	if ((self = [super init])) {
		// Get our main window
		mainWindow = [[DPTestSubject childNamed:@"DPMainWindow"] retain];
	}
	
	return self;
}

- (void)dealloc {
	[mainWindow release]; mainWindow = nil;
	[super dealloc];
}

- (void)windowClosed:(NSNotification *)notif {
	// Make sure the window that was closed is really our window
	[self setStatus:[[notif object] isEqualTo:mainWindow]
	 forPendingTest:@"testMainWindowClosing"];
}

- (void)testMainWindowClosing {
	// Get the window's close button
	DPUIElement *closeButton = [mainWindow valueForAttribute:NSAccessibilityCloseButtonAttribute];
	
	// Watch for main window change notification
	[[DPAccessibilityNotificationCenter defaultCenter] addObserver:self
														  selector:@selector(windowClosed:)
															  name:(NSString *)kAXUIElementDestroyedNotification
															object:mainWindow];
	
	// Close the main window (click the window's close button)
	DPAssert([closeButton performAction:NSAccessibilityPressAction] == nil, @"An error had occurred");
}

@end
